﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Implemented;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Twodi.Utility;
using Twodi.Input.Events;
using Microsoft.Xna.Framework.Input;

namespace Pong.Components
{
    public class Pad : Sprite
    {
        public float Velocity
        {
            get;
            set;
        }

        public Pad(int width, int height, Color color, Game game)
            : base(Helper.CreateSquareTexture(game, width, height, color), game)
        {

        }

        public void AddControlEvent(Keys moveUpKey, Keys moveDownKey)
        {
            KeyboardEvent upControlEvent = new KeyboardEvent(KeyboardEventsType.KeyDown, (sender, e) =>
            {
                if (Position.Y > Limits.Top)
                {
                    Position -= Vector2.UnitY * Velocity;
                }
                return false;
            }, moveUpKey);

            KeyboardEvent downControlEvent = new KeyboardEvent(KeyboardEventsType.KeyDown, (sender, e) =>
            {
                if (Position.Y + Size.Y < Limits.Bottom)
                {
                    Position += Vector2.UnitY * Velocity;
                }
                return false;
            }, moveDownKey);

            this.KeyboardInput.Events.Add(downControlEvent);
            this.KeyboardInput.Events.Add(upControlEvent);
        }
    }
}
